package com.finace.money.presenter;

import android.text.SpannableString;

import com.finace.money.R;
import com.finace.money.common.util.StringUtil;
import com.finace.money.common.util.UIUtil;
import com.finace.money.data.bean.ExtractTickBean;
import com.finace.money.data.bean.HistoryLineBean;
import com.finace.money.data.bean.TickBean;
import com.finace.money.data.bean.chartbean.StickData;

import java.util.ArrayList;

/**
 * Created by zhangpeng on 2018/1/18.
 */

public class KLineViewPresenter extends BasePresenter {

    public KLineViewPresenter() {
    }


    public ArrayList<StickData> getData(ArrayList<HistoryLineBean> lineList, double mPreSettle) {

        ArrayList<StickData> stickData = new ArrayList<>();
        /*for (HistoryLineBean bean : lineList) {
            HistoryLineBean.PayloadBean.MBodyBean mBody = bean.getPayload().getM_Body();

            stickData.add(new StickData(mBody.getM_EndTime(),
                    mBody.getM_Open().getM_Value(),
                    mBody.getM_Close().getM_Value(),
                    mBody.getM_High().getM_Value(),
                    mBody.getM_Low().getM_Value(),
                    mBody.getM_Volume(),
                    mStatusListBean.getPayload().getM_Body().getM_PreSettle().getM_Value(),
                    0,
                    mBody.getM_Money().getM_Value()));
        }*/

        for (int i = 0; i < lineList.size(); i++) {
            HistoryLineBean.MBodyBean m_body = lineList.get(i).getM_Body();
            double zhangdie = 0;
            if(i != 0){
                zhangdie = m_body.getM_Close().getM_Value() - mPreSettle;
            }
            stickData.add(new StickData(m_body.getM_EndTime(),
                    m_body.getM_Open().getM_Value(),
                    m_body.getM_Close().getM_Value(),
                    m_body.getM_High().getM_Value(),
                    m_body.getM_Low().getM_Value(),
                    m_body.getM_Volume(),
                    mPreSettle,
                    zhangdie,
                    m_body.getM_Money().getM_Value()));
        }

        return stickData;
    }

    public ExtractTickBean extractData(TickBean payloadBean, double mPreSettle) {

        double zhangdie = Double.valueOf(payloadBean.getTrade()) - mPreSettle;
        String high = UIUtil.getString(R.string.high) + payloadBean.getHigh();
        SpannableString highStr = null;
        if (Double.valueOf(payloadBean.getHigh()) > mPreSettle) {
            highStr = StringUtil.getSpannableString(high, 0, UIUtil.getString(R.string.high).length(), R.style.text_White899198_12, R.style.text_RedFF3B30_12);
        } else {
            highStr = StringUtil.getSpannableString(high, 0, UIUtil.getString(R.string.high).length(), R.style.text_White899198_12, R.style.text_Green4CD964_12);
        }
        String low = UIUtil.getString(R.string.low) + payloadBean.getLow();
        SpannableString lowStr = null;
        if (Double.valueOf(payloadBean.getLow()) > mPreSettle) {
            lowStr = StringUtil.getSpannableString(low, 0, UIUtil.getString(R.string.low).length(), R.style.text_White899198_12, R.style.text_RedFF3B30_12);
        } else {
            lowStr = StringUtil.getSpannableString(low, 0, UIUtil.getString(R.string.low).length(), R.style.text_White899198_12, R.style.text_Green4CD964_12);
        }

        String pre = UIUtil.getString(R.string.presettle) + payloadBean.getPresettle();
        SpannableString preStr = StringUtil.getSpannableString(pre, 0, UIUtil.getString(R.string.presettle).length(), R.style.text_White899198_12, R.style.text_white_12);

        String oi = UIUtil.getString(R.string.chi_cang) + payloadBean.getOi();
        SpannableString oiStr = StringUtil.getSpannableString(oi, 0, UIUtil.getString(R.string.chi_cang).length(), R.style.text_White899198_12, R.style.text_white_12);

        String size = UIUtil.getString(R.string.size) + payloadBean.getVol();
        SpannableString sizeStr = StringUtil.getSpannableString(size, 0, UIUtil.getString(R.string.size).length(), R.style.text_White899198_12, R.style.text_white_12);

        String change = UIUtil.getString(R.string.day_add) + payloadBean.getChange();
        SpannableString changeStr = StringUtil.getSpannableString(change, 0, UIUtil.getString(R.string.day_add).length(), R.style.text_White899198_12, R.style.text_white_12);

        return new ExtractTickBean(payloadBean.getTrade(),
                zhangdie + "  " + StringUtil.getNumberFormat(String.valueOf(zhangdie / mPreSettle)),
                highStr,
                preStr,
                oiStr,
                lowStr,
                sizeStr,
                changeStr);
    }
}
